package me.fung.wubi.app.view.build_table

import kotlinx.serialization.Serializable
import me.fung.wubi.worker.builder.FileResources
import java.io.File

@Serializable
data class BuildTableModel(
    /**
     * 字典表
     */
    val lexiconFiles: MutableList<String> = arrayListOf(""),
    /**
     * 词频表
     */
    val wordFrequencyFiles: MutableList<String> = arrayListOf(""),
    /**
     * 简码
     */
    val shortCodeFiles: MutableList<String> = arrayListOf(),
    /**
     * 生僻字
     */
    val rareFiles: MutableList<String> = arrayListOf(),
    /**
     * 词组
     */
    val groupFiles: MutableList<String> = arrayListOf(),

    /**
     * 保留简码的全码
     */
    val fullCodeOfShort: Boolean = true,
    /**
     * 普通字自动生成简码（非生僻字和非简码）
     */
    val autoShort: Boolean = false,

    /**
     * 仅单字
     */
    val single: Boolean = false,
    var version: Long = 0

)


fun BuildTableModel.toFileResources(): FileResources {
    return FileResources(
        lexiconFiles = lexiconFiles.filter { it.isNotBlank() }.map { File(it) },
        wordFrequencyFiles = wordFrequencyFiles.filter { it.isNotBlank() }.map { File(it) },
        shortCodeFiles = shortCodeFiles.filter { it.isNotBlank() }.map { File(it) },
        rareFiles = rareFiles.filter { it.isNotBlank() }.map { File(it) },
        groupFiles = groupFiles.filter { it.isNotBlank() }.map { File(it) },
    )
}